package com.uw.tookit;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * This class adapts an image grid displayed on the front page of the app.
 * The grid style and all images used are specified inside this class.
 */
public class ImageAdapter extends BaseAdapter {
    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    // count the total number of items in the grid.
    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    public static String[] getMTextIDs() {
    	return mTextIds;
    }
    
    // create a new View for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
    	
    	//Inflate the layout
        LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View gridView;
        
        if (convertView == null) {  // if it's not recycled, initialize some attributes
        	gridView = new View(mContext);
        	 
			// get layout from grid_item.xml
            gridView = li.inflate(R.layout.grid_item, null);
        } else {
        	gridView = convertView;
        }  
        
        // Add the image
        ImageView imageView = (ImageView)gridView.findViewById(R.id.grid_item_image);;
        //imageView.setLayoutParams(new ImageView.LayoutParams(97, 97));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(3, 3, 3, 3);
        imageView.setImageResource(mThumbIds[position]);
        
        // Add the text
        TextView tv = (TextView)gridView.findViewById(R.id.grid_item_text);
        tv.setText(mTextIds[position]);
        
        return gridView;
    }

    // references to our images
    // could be updated later.
    private Integer[] mThumbIds = {
    		R.drawable.building,
            R.drawable.dining, R.drawable.cafe,
            R.drawable.parking, R.drawable.bus,
            R.drawable.atm, R.drawable.first_aid,
            R.drawable.computer, R.drawable.power,
            R.drawable.library
    };
    
    private static String[] mTextIds = {
    		"Building", "Dining", "Cafe", "Parking", "Bus", "ATM", 
    		"First Aid", "Computer Labs", "Power", "Library"
    };
}
